from openpyxl import load_workbook
import requests, json
from config.Base import Base


def super_simple():
    wb = load_workbook(r'D:\专二\pychon\Auto_wms\cases\min.xlsx')
    base = Base()
    ws = wb['接口测试用例']

    for row in ws.iter_rows(min_row=2, values_only=True):
        method = row[3]  # 获取请求方法
        print(f"请求方法: {method}")

        # 准备请求参数
        params = {}
        if method == 'post':
            params['url'] = row[4]  # URL
            # 处理请求体数据
            if row[6]:  # 请求体
                try:
                    params['json'] = json.loads(row[6])
                except:
                    params['data'] = row[6]

            # 处理请求头
            if row[5]:  # 请求头
                try:
                    params['headers'] = json.loads(row[5])
                except:
                    pass
            if method == 'get':
                params['url'] = row[4]  # URL

            # 调用对应的方法
            try:
                method_func = getattr(base, str(method))
                result = method_func(**params)
                print(f"响应结果: {result}")
            except Exception as e:
                print(f"请求失败: {e}")
# 运行
if __name__ == "__main__":
    super_simple()